<template>
  <!-- 题组列表 -->
  <div class="container">
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-row>
        <el-col :span="6" align="center">
          <el-form-item label="关键字">
            <el-input
              v-model="formInline.user"
              size="small"
              placeholder="根据编号搜索"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="18" :push="15">
          <el-form-item>
            <el-button size="small" @click="onDelList">清除</el-button>
            <el-button type="primary" size="small" @click="queryList"
              >查询</el-button
            >
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="record">
      <i class="el-icon-info"></i>
      <span>数据一共 {{ counts }} 条</span>
    </div>

    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="id" label="编号" width="200" align="center">
      </el-table-column>
      <el-table-column
        prop="questionType"
        label="题型"
        width="180"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="questionIDs"
        width="200"
        label="题目编号"
        align="center"
      >
        <template #default="{ row }">
          <!-- <span>{{ row }}</span> -->
          <p v-for="(item, index) in row.questionIDs" :key="index">
            {{ item.number }}
          </p>
        </template>
      </el-table-column>
      <el-table-column
        prop="addTime"
        width="180"
        label="录入时间"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="totalSeconds" label="答题时间(s)" align="center">
      </el-table-column>
      <el-table-column prop="accuracyRate" label="正确率(%)" align="center">
      </el-table-column>
      <el-table-column prop="userName" label="录入人" align="center">
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="danger"
            plain
            circle
            @click="handleDelete(scope.row)"
            icon="el-icon-delete"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row>
      <el-col :push="9">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="formList.page"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="formList.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="counts"
        >
        </el-pagination>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { randoms, removeRandoms } from '@/api/hmmm/questions.js'
export default {
  data () {
    return {
      counts: 1,
      formInline: {
        user: ''
      },
      formList: {
        page: 1,
        pagesize: 10
      },
      tableData: []
    }
  },
  created () {
    this.getList()
  },
  methods: {
    onSubmit () {
      // console.log('submit!')
    },
    async getList () {
      const { data } = await randoms(this.formList)
      this.tableData = data.items
      this.counts = data.counts
    },
    handleSizeChange (val) {
      this.formList.page = 1
      this.formList.pagesize = val
      this.getList()
    },
    handleCurrentChange (val) {
      this.formList.page = val
      this.getList()
    },
    // 删除
    async handleDelete (rows) {
      // console.log(rows)
      const data = await removeRandoms(rows)
      console.log(data)
      this.getList()
    },
    // 查询
    async queryList () {
      if (this.formInline.user) {
        this.formInline.keyword = this.formInline.user

        const { data } = await randoms(this.formInline)

        this.tableData = data.items
        this.counts = data.counts
      }
    },
    // 清除
    onDelList () {
      this.formInline = {
        user: ''
      }
      this.getList()
    }
  }
}
</script>

<style scoped lang="less">
p {
  padding: 0;
  margin: 0;
  color: #56bdfd;
}
.record {
  width: 1280px;
  height: 40px;
  border-radius: 4px;
  line-height: 40px;
  margin: 0 auto;
  background-color: #f4f4f5;
  font-size: 14px;
  color: #ccc;
  span {
    margin-left: 10px;
  }
  .el-icon-info {
    font-size: 15px;
    color: #909399;
    margin-left: 15px;
  }
}
.el-col {
  margin-top: 20px;
}
.container {
  width: 1320px;
  margin: 10px auto;
  background-color: #fff;
  border-radius: 5px;
}
</style>
